package lib

import (
	"encoding/json"
	"os"
	"os/exec"
	"path/filepath"
)

var ConfigString string //数据库配置
var SysStartTime int64  // time.Now().UnixNano() / int64(time.Millisecond)

func init() {
	file, _ := exec.LookPath(os.Args[0])
	filePath := filepath.Dir(file) + "/config.json"
	ConfigString, _ = FileRead(filePath)
	//fmt.Println("file", filePath)
	if len(ConfigString) == 0 {
		//	fmt.Println("configerr", err)
		//默认配置文件
		ConfigString = `{
			"server":{
				"Domain":"",
				"Prot":"9901"
			},
			"mysql":{
				"Host": "127.0.0.1",
				"Prot":"3306",
				"User":"root",
				"Password": "root",
				"Database": "txgo",
				"Prefix": "tx_",
				"Charset":"utf8mb4"
			},
			"redis":{
				"Host":"127.0.0.1",
				"Port":"6379",
				"Size":"2000",
				"Select":"3"
			}
		}`

		FilerWrite(filePath, ConfigString) //写入默认配置信息
	}

}
func Config() map[string](map[string]interface{}) { //配置文件信息
	config := make(map[string](map[string]interface{}))
	//fmt.Println("ConfigString", ConfigString, len(ConfigString))
	if len(ConfigString) > 0 {
		json.Unmarshal([]byte(ConfigString), &config)
	}

	//fmt.Println("configEnv2", config, len(config))
	//return config

	return config

}
